(function (p) { /* Sai.Calendar.Menu */

    var Menu = function (container) {

        this.today          = container.find("button.today");
        this.prevMonth      = container.find("button.prev-month");
        this.nextMonth      = container.find("button.next-month");
        this.currentDate    = container.find("strong.current-date");
        this.month          = container.find("button.month");
        this.agenda         = container.find("button.agenda");

        this.today.click($.proxy(this.onTodayClick, this));
        
        this.prevMonth.click($.proxy(this.onPrevMonthClick, this));
        this.nextMonth.click($.proxy(this.onNextMonthClick, this));

        this.month.click($.proxy(this.onMonthClick, this));
        this.agenda.click($.proxy(this.onAgendaClick, this));

    }
    Menu.fn = Menu.prototype;


    EventDispatcher.prototype.apply(Menu.prototype);


    Menu.fn.setCurrentDate = function ( year, month ) {

        this.currentDate.text( Sai.Calendar.MONTHS[month] + " de " + year );

    }


    Menu.fn.selectMonth = function () {

        this.month.addClass("selected");
        this.agenda.removeClass("selected");

    }


    Menu.fn.selectAgenda = function () {

        this.month.removeClass("selected");
        this.agenda.addClass("selected");

    }


    Menu.fn.onTodayClick = function () {

        this.dispatchEvent({
            type: Menu.ON_TODAY
        });

    }


    Menu.fn.onPrevMonthClick = function () {

        this.dispatchEvent({
            type: Menu.ON_PREV_MONTH
        });

    }


    Menu.fn.onNextMonthClick = function () {
        
        this.dispatchEvent({
            type: Menu.ON_NEXT_MONTH
        });

    }


    Menu.fn.onMonthClick = function () {

        this.selectMonth();
        this.dispatchEvent({
            type: Menu.ON_MONTH_SELECT
        });

    }


    Menu.fn.onAgendaClick = function () {

        this.selectAgenda();
        this.dispatchEvent({
            type: Menu.ON_AGENDA_SELECT
        });

    }

    Menu.ON_TODAY           = "onToday";
    Menu.ON_PREV_MONTH      = "onPrevMonth";
    Menu.ON_NEXT_MONTH      = "onNextMonth";
    Menu.ON_MONTH_SELECT    = "onMonthSelect";
    Menu.ON_AGENDA_SELECT   = "onAgendaSelect";

    p.Menu = Menu;

})(Sai.Calendar);